package com.skypan.myapplication.fragment;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.skypan.myapplication.R;
import com.skypan.myapplication.RegisterActivity;
import com.skypan.myapplication.bean.RegisterR;
import com.skypan.myapplication.http.RegisterCallback;
import com.zhy.http.okhttp.OkHttpUtils;

import okhttp3.Call;
//生产企业管理人员——设置当日或当月加密字符串


public class SecretCodeFragment extends BaseFragment{

    @ViewInject(R.id.btn_secretcode)
    private Button btnsecretcode;
    @ViewInject(R.id.txt_secretcode)
    private TextView txtsecretcode;
    @ViewInject(R.id.etxt_phone)
    private EditText etxtphone;

    String url ="http://39.105.165.31:8080/" ;

    @Override
    public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_secretcode,container,false);
    }

    @Override
    public void init() {

    }

    @OnClick(R.id.btn_secretcode)
    public void Reset(View view){
        final EditText et = new EditText(getContext());
        new AlertDialog.Builder(getContext()).setTitle("请输入加密字符串")
                .setView(et)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //按下确定键后的事件
                        postcode(et.getText().toString());
                        Toast.makeText(getContext(), et.getText().toString(),Toast.LENGTH_LONG).show();
                    }
                }).setNegativeButton("取消",null).show();
    }

    public void postcode(String code)
    {
        OkHttpUtils
                .post()//
                .url(url)//
                .addParams("userAccount", code)//
                .build()//
                .execute(new RegisterCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(getContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
                    }
                    public void onResponse(RegisterR response, int id) {
                            Toast.makeText(getContext(),response.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                });
    }

}
